<template>
  <view class="login-container">
    <view class="login-form">
      <u-field
        v-model="password"
        label="旧密码"
        required
        password
        placeholder="请填写旧密码"
      >
      </u-field>
      <u-field
        v-model="newPassword"
        label="新密码"
        required
        password
        placeholder="请填写新密码"
      >
      </u-field>
      <u-field
        v-model="newPassword2"
        label="确认密码"
        required
        password
        placeholder="请确认新密码"
      >
      </u-field>
      <view class="login-btns">
        <u-button type="primary" class="login-btn" @click="onSubmit">确认修改</u-button>
      </view>
      
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        password: '',
        newPassword: '',
        newPassword2: '',
      }
    },
    methods: {
      onSubmit() {
        if (this.newPassword2 !== this.newPassword) {
          uni.showModal({
            title: '重复密码须和新密码一致',
            showCancel: false,
          })
          return
        }
        const data = {
          oldPassword: this.password,
          newPassword: this.newPassword
        }
        this.$http({
          url: '/my/editPassword',
          data
        }).then(res => {
          uni.showToast({
            title: '修改成功'
          })
          setTimeout(() => {
            wx.navigateBack()
          }, 1500)
        }).catch(err=> {
          uni.showModal({
            title: err.msg,
            showCancel: false,
          })
        })
      }
    }
  }
</script>

<style lang="less">
  .login-container{
    .login-lgoo{
      font-size: 34rpx;
      text-align: center;
      font-weight: bold;
      padding: 100rpx 50rpx;
    }
    .login-form{
      padding: 0 30rpx;
    }
    .login-btns{
      padding-top: 30rpx;
    }
    .login-btn{
      margin-top: 30rpx;
    }
  }
</style>
